from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-04 14:06:28.071635
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 04, Jan, 2022
Time: 14:06:33
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6815
Nobs: 526.000 HQIC: -48.1256
Log likelihood: 6104.92 FPE: 9.44595e-22
AIC: -48.4113 Det(Omega_mle): 7.97323e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.372919 0.076296 4.888 0.000
L1.Burgenland 0.098359 0.043188 2.277 0.023
L1.Kärnten -0.114053 0.022251 -5.126 0.000
L1.Niederösterreich 0.173979 0.089740 1.939 0.053
L1.Oberösterreich 0.103844 0.089519 1.160 0.246
L1.Salzburg 0.279795 0.046113 6.068 0.000
L1.Steiermark 0.030299 0.059970 0.505 0.613
L1.Tirol 0.109815 0.048383 2.270 0.023
L1.Vorarlberg -0.078240 0.042737 -1.831 0.067
L1.Wien 0.029195 0.080554 0.362 0.717
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.046217 0.167952 0.275 0.783
L1.Burgenland -0.042633 0.095070 -0.448 0.654
L1.Kärnten 0.040363 0.048982 0.824 0.410
L1.Niederösterreich -0.211286 0.197544 -1.070 0.285
L1.Oberösterreich 0.455854 0.197058 2.313 0.021
L1.Salzburg 0.293681 0.101508 2.893 0.004
L1.Steiermark 0.117785 0.132012 0.892 0.372
L1.Tirol 0.305656 0.106506 2.870 0.004
L1.Vorarlberg 0.018094 0.094077 0.192 0.847
L1.Wien -0.014515 0.177324 -0.082 0.935
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.212860 0.038916 5.470 0.000
L1.Burgenland 0.093198 0.022029 4.231 0.000
L1.Kärnten -0.006155 0.011350 -0.542 0.588
L1.Niederösterreich 0.228198 0.045773 4.985 0.000
L1.Oberösterreich 0.159058 0.045661 3.483 0.000
L1.Salzburg 0.039667 0.023521 1.686 0.092
L1.Steiermark 0.028067 0.030589 0.918 0.359
L1.Tirol 0.080315 0.024679 3.254 0.001
L1.Vorarlberg 0.055165 0.021799 2.531 0.011
L1.Wien 0.110894 0.041088 2.699 0.007
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.147786 0.038924 3.797 0.000
L1.Burgenland 0.040860 0.022033 1.854 0.064
L1.Kärnten -0.013530 0.011352 -1.192 0.233
L1.Niederösterreich 0.162156 0.045783 3.542 0.000
L1.Oberösterreich 0.332314 0.045670 7.276 0.000
L1.Salzburg 0.102958 0.023525 4.376 0.000
L1.Steiermark 0.110452 0.030595 3.610 0.000
L1.Tirol 0.091258 0.024684 3.697 0.000
L1.Vorarlberg 0.054582 0.021803 2.503 0.012
L1.Wien -0.029661 0.041096 -0.722 0.470
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121932 0.073090 1.668 0.095
L1.Burgenland -0.040524 0.041373 -0.979 0.327
L1.Kärnten -0.040782 0.021316 -1.913 0.056
L1.Niederösterreich 0.136741 0.085968 1.591 0.112
L1.Oberösterreich 0.170182 0.085756 1.984 0.047
L1.Salzburg 0.273915 0.044175 6.201 0.000
L1.Steiermark 0.071700 0.057450 1.248 0.212
L1.Tirol 0.141727 0.046350 3.058 0.002
L1.Vorarlberg 0.096997 0.040941 2.369 0.018
L1.Wien 0.071776 0.077169 0.930 0.352
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.089590 0.057506 1.558 0.119
L1.Burgenland 0.018161 0.032552 0.558 0.577
L1.Kärnten 0.052721 0.016771 3.144 0.002
L1.Niederösterreich 0.182504 0.067638 2.698 0.007
L1.Oberösterreich 0.326466 0.067471 4.839 0.000
L1.Salzburg 0.044280 0.034756 1.274 0.203
L1.Steiermark -0.000476 0.045200 -0.011 0.992
L1.Tirol 0.124146 0.036467 3.404 0.001
L1.Vorarlberg 0.062833 0.032211 1.951 0.051
L1.Wien 0.100841 0.060715 1.661 0.097
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159371 0.069743 2.285 0.022
L1.Burgenland 0.008989 0.039479 0.228 0.820
L1.Kärnten -0.063591 0.020340 -3.126 0.002
L1.Niederösterreich -0.110373 0.082031 -1.345 0.178
L1.Oberösterreich 0.219942 0.081830 2.688 0.007
L1.Salzburg 0.049430 0.042152 1.173 0.241
L1.Steiermark 0.257673 0.054819 4.700 0.000
L1.Tirol 0.493583 0.044227 11.160 0.000
L1.Vorarlberg 0.065592 0.039066 1.679 0.093
L1.Wien -0.076799 0.073635 -1.043 0.297
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148531 0.077158 1.925 0.054
L1.Burgenland -0.009876 0.043676 -0.226 0.821
L1.Kärnten 0.064005 0.022503 2.844 0.004
L1.Niederösterreich 0.172307 0.090753 1.899 0.058
L1.Oberösterreich -0.071199 0.090530 -0.786 0.432
L1.Salzburg 0.217046 0.046634 4.654 0.000
L1.Steiermark 0.141123 0.060647 2.327 0.020
L1.Tirol 0.052456 0.048930 1.072 0.284
L1.Vorarlberg 0.144689 0.043220 3.348 0.001
L1.Wien 0.143683 0.081464 1.764 0.078
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.448063 0.043922 10.201 0.000
L1.Burgenland -0.002497 0.024862 -0.100 0.920
L1.Kärnten -0.017236 0.012810 -1.346 0.178
L1.Niederösterreich 0.185856 0.051661 3.598 0.000
L1.Oberösterreich 0.229258 0.051534 4.449 0.000
L1.Salzburg 0.031687 0.026546 1.194 0.233
L1.Steiermark -0.014437 0.034523 -0.418 0.676
L1.Tirol 0.081989 0.027853 2.944 0.003
L1.Vorarlberg 0.050639 0.024603 2.058 0.040
L1.Wien 0.009586 0.046373 0.207 0.836
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.030141 0.090171 0.158377 0.138381 0.073718 0.077037 0.016193 0.206933
Kärnten 0.030141 1.000000 -0.031345 0.131168 0.045464 0.079232 0.448546 -0.075673 0.092374
Niederösterreich 0.090171 -0.031345 1.000000 0.298743 0.111413 0.256056 0.053855 0.146826 0.261303
Oberösterreich 0.158377 0.131168 0.298743 1.000000 0.204749 0.285657 0.160732 0.128776 0.209483
Salzburg 0.138381 0.045464 0.111413 0.204749 1.000000 0.116992 0.069024 0.104397 0.091171
Steiermark 0.073718 0.079232 0.256056 0.285657 0.116992 1.000000 0.127409 0.093012 0.008114
Tirol 0.077037 0.448546 0.053855 0.160732 0.069024 0.127409 1.000000 0.058118 0.138209
Vorarlberg 0.016193 -0.075673 0.146826 0.128776 0.104397 0.093012 0.058118 1.000000 -0.018243
Wien 0.206933 0.092374 0.261303 0.209483 0.091171 0.008114 0.138209 -0.018243 1.000000